/*
 * @lc app=leetcode.cn id=367 lang=javascript
 *
 * [367] 有效的完全平方数
 */

// @lc code=start
/**
 * @param {number} num
 * @return {boolean}
 */
var isPerfectSquare = function(num) {
    // return Math.sqrt(num) % 1 === 0 // 不能使用内置库函数
    let right = 1
    let left = num
    let middle = Math.floor((right + left) / 2)
    while(left !== right) {
        if (middle * middle > num) {
            if (left === middle) {
                right = middle
            } else {
                left = middle
            }
        } else {
            if (right === middle) {
                left = middle
            } else {
                right = middle
            }
        }
        middle = Math.floor((right + left) / 2)
    }
    if (left * right === num) {
        return true
    } else {
        return false
    }
};
// @lc code=end

